﻿using System;

namespace Game.Lib.CSG
{
    public struct Intersection
    {
        public static readonly Intersection Missed = new Intersection(new Ray(), 0f, Vector3.NegAllOne);

        public float Distance;
        public Vector3 Pos;
        public Vector3 Normal;

        public bool Miss
        {
            get
            {
                return (float)Math.Abs(Normal.Magnitude() - 1f) > Utils.Epsilon;
            }
        }

        public Intersection(Ray r, Vector3 pos, Vector3 norm)
        {
            Distance = Vector3.Distance(r.Start, pos);
            Pos = pos;
            Normal = norm;
        }

        public Intersection(Ray r, float d, Vector3 norm)
        {
            Distance = d;
            Pos = r.Get(d);
            Normal = norm;
        }
    }
}
